#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
typedef int TreeDataType;
typedef struct OderTree
{
	TreeDataType* arr;
	int capacity;
	int size;
}Tree;
void TreeInit(Tree* plist)
{
	assert(plist);
	plist->arr = NULL;
	plist->capacity = plist->size = 0;
}
void AdjustTreeCapacity(Tree* plist)
{
	assert(plist);
	if (plist->capacity == plist->size)
	{
		if (plist->capacity == 0)
		{
			plist->capacity = 4;
		}
		else
		{
			plist->capacity = 2 * plist->capacity;
		}
		TreeDataType* newarr = (TreeDataType*)realloc(plist->arr, sizeof(TreeDataType) * 2 * plist->capacity);
		if (newarr == NULL)
		{
			perror("realloc fail!");
			return;
		}
		plist->arr = newarr;
	}
}
void TreeTailPush(Tree* plist, TreeDataType x)
{
	assert(plist);
	AdjustTreeCapacity(plist);
	plist->arr[plist->size] = x;
	plist->size++;
}
void TreeTailDelete(Tree* plist)
{
	assert(plist);
	plist->size--;
}
void TreePrint(Tree* plist)
{
	assert(plist);
	for (int i = 0; i<plist->size; i++)
	{
		printf("%d ", plist->arr[i]);
	}
}
void TreeDestroy(Tree* plist)
{
	assert(plist);
	plist->capacity = plist->size = 0;
	free(plist->arr);
}
int main()
{
	Tree tree;
	TreeInit(&tree);
	TreeTailPush(&tree, 1);
	TreeTailPush(&tree, 2);
	TreeTailPush(&tree, 3);
	TreeTailPush(&tree, 4);
	/*TreeTailPush(&tree, 5);
	TreeTailPush(&tree, 6);
	TreeTailPush(&tree, 7);
	TreeTailDelete(&tree);
	TreeTailDelete(&tree);
	TreeTailDelete(&tree);*/
	TreeDestroy(&tree);
	TreePrint(&tree);
	return 0;
}